#ifndef __GLOBAL_H
#define __GLOBAL_H
#include "stdint.h"
#include "bool.h"

#define UNUSED __attribute__((unused))
#define div_round_up(value,s) ((value+s-1)/(s))

#define VK_PD_BASE 0xfffff000
//kernal selector
#define RPL_0 0
#define RPL_3 3

#define TI_GDT 0
#define TI_LDT 1

#define K_CODE_SEL (1<<3) | (TI_GDT<<2) | (RPL_0)
#define K_DATA_SEL (2<<3) | (TI_GDT<<2) | (RPL_0)
#define K_VGA_SEL  (3<<3) | (TI_GDT<<2) | (RPL_0)
#define U_CODE_SEL (4<<3) | (TI_GDT<<2) | (RPL_3)
#define U_DATA_SEL (5<<3) | (TI_GDT<<2) | (RPL_3)
#define TSS_SEL	   (6<<3) | (TI_GDT<<2) | (RPL_0)
#define U_STACK_SEL U_DATA_SEL
#define K_STACK_SEL K_DATA_SEL
#define GDT_TABLE 0xc0000504
#define GDT_LEN 7*8

#define G_4K 0xf000
#define G_1  0x7000

#define TSS_ATTR 0x1089
#define U_CODE_X 0xf8
#define U_DATA_RW 0xf2

#define DPL0 0
#define DPL3 3

#define P 1

#define GATE_TYPE_INTR 0x0e

#define GATE_DES_ATTR  (P<<7)|(DPL0<<5)|GATE_TYPE_INTR
#define SYSCALL_DES_ATTR (P<<7)|(DPL3<<5)|GATE_TYPE_INTR

#define TEXT_MODE_LINE_ROW 80
#define TEXT_MODE_LINE_COL 25
//PIC define here

#define PIC_M_CTRL 0x20
#define PIC_M_DATA 0x21
#define PIC_S_CTRL 0xa0
#define PIC_S_DATA 0xa1

#define NULL ((void*)0)

//cpu eflags
#define EF_MBS 1<<1
#define EF_IF  1<<9

#endif
